/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
 * Description: 上机编程认证
 * Note: 缺省代码仅供参考，可自行决定使用、修改或删除
 */
#include <iostream>
#include <string>
using namespace std;

class Solution {
private:
    static int BinaryToDecimalPositive(const string &binaryString) {
        int res = 0;
        for (int i = 0; i < binaryString.size(); i++) {
            res *= 2;
            res += binaryString[i] - '0';
        }
        return res;
    }

    static int BinaryToDecimalNegative(const string &binaryString) {
        //逐位取反，再加1便是它的绝对值
        int res = 0;
        for (int i = 1; i < binaryString.size(); i++) {
            res *= 2;
            res += 1 - (binaryString[i] - '0');
        }
        return -(res + 1);
    }

public:
    int BinaryToDecimal(const string &binaryString) const {
        //判断正负
        if (binaryString[0] == '1' and binaryString.size() == 32) {
            return BinaryToDecimalNegative(binaryString);
        }
        return BinaryToDecimalPositive(binaryString);
    }
};

inline string ReadLine() {
    string line;
    getline(cin, line);
    return line;
}

int main() {
    string binaryString = ReadLine();
    Solution solu;
    int result = solu.BinaryToDecimal(binaryString);
    cout << result << endl;
    return 0;
}
